<template>
  <el-menu
      :default-active="this.$store.state.menus.editableTabsValue"
      class="el-menu-vertical-demo"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b">
    <router-link to="/index">
      <el-menu-item index="Index" @click="selectMenu({name: 'Index', title: '首页'})">
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </template>
      </el-menu-item>
    </router-link>
    <!--动态侧边栏菜单, 目前写死了二层菜单-->
    <el-submenu :index="menu.name" v-for="menu in menuList">
      <template slot="title">
        <i :class="menu.icon"></i>
        <span>{{ menu.title }}</span>
      </template>
      <router-link :to="item.path" v-for="item in menu.children">
        <el-menu-item :index="item.name" @click="selectMenu(item)">
          <template slot="title">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </template>
        </el-menu-item>
      </router-link>
    </el-submenu>
  </el-menu>

  <!-- 导航菜单 -->
  <!--<div>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" router>

      <el-menu-item index="Index" @click="selectMenu({name: 'Index', title: '首页'})">
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </template>
      </el-menu-item>

      <template slot="title" v-for="menu in menuList">
        &lt;!&ndash;有二级子菜单&ndash;&gt;
        <el-submenu index="1" v-if="menu.children.length > 0">
          <i class="el-icon-menu"></i>
          <span slot="title">导航二</span>

        </el-submenu>
        &lt;!&ndash;没有子菜单&ndash;&gt;
        <el-menu-item :index="menu.path" v-else>
          <i :class="menu.icon"></i>
          <span slot="title">{{ menu.title }}</span>
        </el-menu-item>
      </template>

      <el-submenu :index="menu.name" v-for="menu in menuList">
        <template slot="title">
          <i :class="menu.icon"></i>
          <span>{{ menu.title }}</span>
        </template>
        <router-link :to="item.path" v-for="item in menu.children">
          <el-menu-item :index="item.name" @click="selectMenu(item)">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
          </el-menu-item>
        </router-link>
      </el-submenu>

      &lt;!&ndash;<el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span slot="title">导航一</span>
        </template>
        <el-menu-item-group>
          <span slot="title">分组一</span>
          <el-menu-item index="1-1">选项1</el-menu-item>
          <el-menu-item index="1-2">选项2</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分组2">
          <el-menu-item index="1-3">选项3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <span slot="title">选项4</span>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu>
      </el-submenu>
      <el-menu-item index="2">
        <i class="el-icon-menu"></i>
        <span slot="title">导航二</span>
      </el-menu-item>
      <el-menu-item index="3" disabled>
        <i class="el-icon-document"></i>
        <span slot="title">导航三</span>
      </el-menu-item>&ndash;&gt;
    </el-menu>
  </div>-->

</template>

<script>
import Teacher from "@/views/admin/Teacher";
export default {
  name: "SideMenu",
  components: {Teacher},
  data() {
    return {
      // isCollapse: true
    }
  },
  computed: {
    menuList: {
      get() {
        return this.$store.state.menus.menuList
      }
    }
  },
  created() {
    console.log("menuList")
    console.log(this.menuList)
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    selectMenu(item) {
      // this.$store.commit("addTab", item)
      console.log(item)
      let obj = {name: item.name, title: item.title}
      this.$store.commit("addTabs", obj)
    }
  }
}
</script>

<style scoped>
.el-menu-vertical-demo {
  height: 100%;
}
</style>